

library("rstudioapi")     
##Set working directory
setwd(dirname(getActiveDocumentContext()$path))
library("readxl") 
require(miceadds)
library(data.table)
library(tidyverse)
library(DescTools)
library(htmlTable)
library(stargazer)
library(estimatr)
library(tidyverse)
library(DescTools)
require(dplyr)

load("FinalFinalSP20062023Full1-6.RData")

combo = final_finalSP
combo = combo[-which(is.na(combo$T)==TRUE),]
dim(combo)

##1: 
require(dplyr)
# Number of villages: 
nb_vil_full = length(na.omit(unique(combo$Q123)))
nb_vil <- combo %>% group_by(T, Q123) %>% summarise(n = n()) %>% summarise(n = n())
nb_vil_pla = nb_vil$n[nb_vil$T == "Placebo"][1]
nb_vil_cdc = nb_vil$n[nb_vil$T == "CDC health"][1]
nb_vil_lc = nb_vil$n[nb_vil$T == "Low Cash"][1]
nb_vil_hc = nb_vil$n[nb_vil$T == "High Cash"][1]

##2: 
# Number of observations:
nb_treatment <- combo %>% group_by(T) %>% summarise(n = n())
nb_t1 <- nb_treatment$n[nb_treatment$T == "Placebo"][1]
nb_t2 <- nb_treatment$n[nb_treatment$T == "CDC health"][1]
nb_t3 <- nb_treatment$n[nb_treatment$T == "Low Cash"][1]
nb_t4 <- nb_treatment$n[nb_treatment$T == "High Cash"][1]
nb_total <- sum(nb_treatment$n)

##3: 
# % Female
gender_full <- combo%>%  group_by(Q10.3) %>% summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))
female_full <- gender_full$percentage[gender_full$Q10.3 == "Female"][1]

# % Female per treatment
gender_treatment <- combo %>%  group_by(T, Q10.3) %>%
  summarise(n = n()) %>%   mutate(percentage = 100 * n / sum(n))
female_pla <- gender_treatment$percentage[gender_treatment$Q10.3 == "Female" & gender_treatment$T == "Placebo"][1]
female_cdc <- gender_treatment$percentage[gender_treatment$Q10.3 == "Female" & gender_treatment$T == "CDC health"][1]
female_lc <- gender_treatment$percentage[gender_treatment$Q10.3 == "Female" & gender_treatment$T == "Low Cash"][1]
female_hc <- gender_treatment$percentage[gender_treatment$Q10.3 == "Female" & gender_treatment$T == "High Cash"][1]

# SD for Female variable: 
f_tab = combo[,c("T", "Q10.3")]
f_tab$Female = ifelse(f_tab$Q10.3=="Female", 1, 0)
female_sd <- f_tab %>%
  group_by(T) %>%
  summarise(sd = sd(Female, na.rm = TRUE))
female_pla_sd <- as.numeric(female_sd[which(female_sd$T=="Placebo"),][2])*100
female_cdc_sd <- as.numeric(female_sd[which(female_sd$T=="CDC health"),][2])*100
female_lc_sd <- as.numeric(female_sd[which(female_sd$T=="Low Cash"),][2])*100
female_hc_sd <-as.numeric(female_sd[which(female_sd$T=="High Cash"),][2])*100
female_total_sd = sd(f_tab$Female, na.rm = TRUE)*100

##4: 
# Vaccine Actual Vaccine 
combo_small = combo
combo_small = combo_small[which(combo_small$`District number`%in% c(1,2,3,4)),]
combo_small$ActVacApril = ifelse(combo_small$ActVacApril %in% c("1"), 1, 0) 

vaccination_full = combo_small %>%  group_by(ActVacApril) %>% summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))
vaccined_full = vaccination_full$percentage[vaccination_full$ActVacApril == 1][1]

vaccine_treatment <- combo_small %>%  group_by(T, ActVacApril) %>%
  summarise(n = n()) %>%   mutate(percentage = 100 * n / sum(n))
vaccine_pla <- vaccine_treatment$percentage[vaccine_treatment$ActVacApril == 1 & vaccine_treatment$T == "Placebo"][1]
vaccine_cdc <- vaccine_treatment$percentage[vaccine_treatment$ActVacApril == 1 & vaccine_treatment$T == "CDC health"][1]
vaccine_lc <- vaccine_treatment$percentage[vaccine_treatment$ActVacApril == 1 & vaccine_treatment$T == "Low Cash"][1]
vaccine_hc <- vaccine_treatment$percentage[vaccine_treatment$ActVacApril == 1 & vaccine_treatment$T == "High Cash"][1]

# Standard deviations: 
v_tab = combo_small[,c("T", "ActVacApril")]
v_tab$vaccine = ifelse(v_tab$ActVacApril==1, 1, 0)
vaccine_sd <- v_tab %>%
  group_by(T) %>%
  summarise(sd = sd(vaccine, na.rm = TRUE))
vaccine_pla_sd <- as.numeric(vaccine_sd[which(vaccine_sd$T=="Placebo"),][2])*100
vaccine_cdc_sd <- as.numeric(vaccine_sd[which(vaccine_sd$T=="CDC health"),][2])*100
vaccine_lc_sd <- as.numeric(vaccine_sd[which(vaccine_sd$T=="Low Cash"),][2])*100
vaccine_hc_sd <-as.numeric(vaccine_sd[which(vaccine_sd$T=="High Cash"),][2])*100
vaccine_total_sd = sd(v_tab$vaccine, na.rm = TRUE)*100

##5: 
# Vaccine Dose 1: 
combo_small = combo[-which(is.na(combo$vaccine_reported)==TRUE),]
vaccination_full2 = combo_small %>%  group_by(vaccine_reported) %>% summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))
vaccined_full2 = vaccination_full2$percentage[vaccination_full2$vaccine_reported == 1][1]

vaccine_treatment2 <- combo_small %>%  group_by(T, vaccine_reported) %>%
  summarise(n = n()) %>%   mutate(percentage = 100 * n / sum(n))
vaccine_pla2 <- vaccine_treatment2$percentage[vaccine_treatment2$vaccine_reported == 1 & vaccine_treatment2$T == "Placebo"][1]
vaccine_cdc2 <- vaccine_treatment2$percentage[vaccine_treatment2$vaccine_reported == 1 & vaccine_treatment2$T == "CDC health"][1]
vaccine_lc2 <- vaccine_treatment2$percentage[vaccine_treatment2$vaccine_reported == 1 & vaccine_treatment2$T == "Low Cash"][1]
vaccine_hc2 <- vaccine_treatment2$percentage[vaccine_treatment2$vaccine_reported == 1 & vaccine_treatment2$T == "High Cash"][1]

# Standard deviations: 
v_tab = combo_small[,c("T", "vaccine_reported")]
v_tab$vaccine = ifelse(v_tab$vaccine_reported==1, 1, 0)
vaccine_sd <- v_tab %>%
  group_by(T) %>%
  summarise(sd = sd(vaccine, na.rm = TRUE))
vaccine_pla_sd2 <- as.numeric(vaccine_sd[which(vaccine_sd$T=="Placebo"),][2])*100
vaccine_cdc_sd2 <- as.numeric(vaccine_sd[which(vaccine_sd$T=="CDC health"),][2])*100
vaccine_lc_sd2 <- as.numeric(vaccine_sd[which(vaccine_sd$T=="Low Cash"),][2])*100
vaccine_hc_sd2 <-as.numeric(vaccine_sd[which(vaccine_sd$T=="High Cash"),][2])*100
vaccine_total_sd2 = sd(v_tab$vaccine, na.rm = TRUE)*100

##6: 
# Vaccine3: 
combo_small = combo[-which(is.na(combo$Vaccine_Partner)==TRUE),]
vaccination_full3 = combo_small %>%  group_by(Vaccine_Partner) %>% summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))
vaccined_full3 = vaccination_full3$percentage[vaccination_full3$Vaccine_Partner == "Yes"][1]

vaccine_treatment3 <- combo_small %>%  group_by(T, Vaccine_Partner) %>%
  summarise(n = n()) %>%   mutate(percentage = 100 * n / sum(n))
vaccine_pla3 <- vaccine_treatment3$percentage[vaccine_treatment3$Vaccine_Partner == "Yes" & vaccine_treatment3$T == "Placebo"][1]
vaccine_cdc3 <- vaccine_treatment3$percentage[vaccine_treatment3$Vaccine_Partner == "Yes" & vaccine_treatment3$T == "CDC health"][1]
vaccine_lc3 <- vaccine_treatment3$percentage[vaccine_treatment3$Vaccine_Partner == "Yes" & vaccine_treatment3$T == "Low Cash"][1]
vaccine_hc3 <- vaccine_treatment3$percentage[vaccine_treatment3$Vaccine_Partner == "Yes" & vaccine_treatment3$T == "High Cash"][1]

# Standard deviations: 
v_tab = combo_small[,c("T", "Vaccine_Partner")]
v_tab$vaccine = ifelse(v_tab$Vaccine_Partner=="Yes", 1, 0)
vaccine_sd <- v_tab %>%
  group_by(T) %>%
  summarise(sd = sd(vaccine, na.rm = TRUE))
vaccine_pla_sd3 <- as.numeric(vaccine_sd[which(vaccine_sd$T=="Placebo"),][2])*100
vaccine_cdc_sd3 <- as.numeric(vaccine_sd[which(vaccine_sd$T=="CDC health"),][2])*100
vaccine_lc_sd3 <- as.numeric(vaccine_sd[which(vaccine_sd$T=="Low Cash"),][2])*100
vaccine_hc_sd3 <-as.numeric(vaccine_sd[which(vaccine_sd$T=="High Cash"),][2])*100
vaccine_total_sd3 = sd(v_tab$vaccine, na.rm = TRUE)*100

##7: 
# Vaccine4: 
combo_small = combo[-which(is.na(combo$Vaccine_Partner_Verify)==TRUE),]
vaccination_full4 = combo_small %>%  group_by(Vaccine_Partner_Verify) %>% summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))
vaccined_full4 = vaccination_full4$percentage[vaccination_full4$Vaccine_Partner_Verify == "Yes"][1]

vaccine_treatment4 <- combo_small %>%  group_by(T, Vaccine_Partner_Verify) %>%
  summarise(n = n()) %>%   mutate(percentage = 100 * n / sum(n))
vaccine_pla4 <- vaccine_treatment4$percentage[vaccine_treatment4$Vaccine_Partner_Verify == "Yes" & vaccine_treatment4$T == "Placebo"][1]
vaccine_cdc4 <- vaccine_treatment4$percentage[vaccine_treatment4$Vaccine_Partner_Verify == "Yes" & vaccine_treatment4$T == "CDC health"][1]
vaccine_lc4 <- vaccine_treatment4$percentage[vaccine_treatment4$Vaccine_Partner_Verify == "Yes" & vaccine_treatment4$T == "Low Cash"][1]
vaccine_hc4 <- vaccine_treatment4$percentage[vaccine_treatment4$Vaccine_Partner_Verify == "Yes" & vaccine_treatment4$T == "High Cash"][1]

# Standard deviations: 
v_tab = combo_small[,c("T", "Vaccine_Partner_Verify")]
v_tab$vaccine = ifelse(v_tab$Vaccine_Partner_Verify=="Yes", 1, 0)
vaccine_sd <- v_tab %>%
  group_by(T) %>%
  summarise(sd = sd(vaccine, na.rm = TRUE))
vaccine_pla_sd4 <- as.numeric(vaccine_sd[which(vaccine_sd$T=="Placebo"),][2])*100
vaccine_cdc_sd4 <- as.numeric(vaccine_sd[which(vaccine_sd$T=="CDC health"),][2])*100
vaccine_lc_sd4 <- as.numeric(vaccine_sd[which(vaccine_sd$T=="Low Cash"),][2])*100
vaccine_hc_sd4 <-as.numeric(vaccine_sd[which(vaccine_sd$T=="High Cash"),][2])*100
vaccine_total_sd4 = sd(v_tab$vaccine, na.rm = TRUE)*100

##8: 
# Solar buy / not: 
Solar = combo %>%  group_by(Solar) %>% summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))
Solar = Solar$percentage[Solar$Solar == "Yes, I have recently purchased a solar charging device"][1]

Solar2 <- combo %>%  group_by(T, Solar) %>%
  summarise(n = n()) %>%   mutate(percentage = 100 * n / sum(n))
Solar_pla <- Solar2$percentage[Solar2$Solar == "Yes, I have recently purchased a solar charging device" & Solar2$T == "Placebo"][1]
Solar_cdc <- Solar2$percentage[Solar2$Solar == "Yes, I have recently purchased a solar charging device" & Solar2$T == "CDC health"][1]
Solar_lc <- Solar2$percentage[Solar2$Solar == "Yes, I have recently purchased a solar charging device" & Solar2$T == "Low Cash"][1]
Solar_hc <- Solar2$percentage[Solar2$Solar == "Yes, I have recently purchased a solar charging device" & Solar2$T == "High Cash"][1]

# Standard deviations: 
v_tab = combo[,c("T", "Solar")]
v_tab$vaccine = ifelse(v_tab$Solar=="Yes, I have recently purchased a solar charging device", 1, 0)
Solar_sd <- v_tab %>%
  group_by(T) %>%
  summarise(sd = sd(vaccine, na.rm = TRUE))
Solar_pla_sd <- as.numeric(Solar_sd[which(Solar_sd$T=="Placebo"),][2])*100
Solar_cdc_sd <- as.numeric(Solar_sd[which(Solar_sd$T=="CDC health"),][2])*100
Solar_lc_sd <- as.numeric(Solar_sd[which(Solar_sd$T=="Low Cash"),][2])*100
Solar_hc_sd <-as.numeric(Solar_sd[which(Solar_sd$T=="High Cash"),][2])*100
Solar_total_sd = sd(v_tab$vaccine, na.rm = TRUE)*100


##9: 
# How many villiges have you visited last month: 
combo$Village_Visit_Month = as.numeric(combo$Village_Visit_Month)
vil_month_total = mean(as.numeric(combo$Village_Visit_Month), na.rm = TRUE)

vil_month_tr <- combo %>%
  group_by(T) %>%
  summarise(mean = mean(Village_Visit_Month,  na.rm = TRUE))

vil_month_tr1 = vil_month_tr$mean[vil_month_tr$T == "Placebo"][1]
vil_month_tr2 = vil_month_tr$mean[vil_month_tr$T == "CDC health"][1]
vil_month_tr3 = vil_month_tr$mean[vil_month_tr$T == "Low Cash"][1]
vil_month_tr4 = vil_month_tr$mean[vil_month_tr$T == "High Cash"][1]

# standard deviations
vil_month_total_sd = sd(as.numeric(combo$Village_Visit_Month), na.rm = TRUE)

vil_month_tr_sd <- combo %>%
  group_by(T) %>%
  summarise(mean = sd(Village_Visit_Month,  na.rm = TRUE))

vil_month_tr1_sd = vil_month_tr_sd$mean[vil_month_tr_sd$T == "Placebo"][1]
vil_month_tr2_sd = vil_month_tr_sd$mean[vil_month_tr_sd$T == "CDC health"][1]
vil_month_tr3_sd = vil_month_tr_sd$mean[vil_month_tr_sd$T == "Low Cash"][1]
vil_month_tr4_sd = vil_month_tr_sd$mean[vil_month_tr_sd$T == "High Cash"][1]

## 10: 
# How many villiges have you visited last year: 
vil_year_total = mean(as.numeric(combo$Village_Visit_Year), na.rm = TRUE)
combo$Village_Visit_Year = as.numeric(combo$Village_Visit_Year)

vil_year_tr <- combo %>%
  group_by(T) %>%
  summarise(mean = mean(Village_Visit_Year,  na.rm = TRUE))

vil_year_tr1 = vil_year_tr$mean[vil_year_tr$T == "Placebo"][1]
vil_year_tr2 = vil_year_tr$mean[vil_year_tr$T == "CDC health"][1]
vil_year_tr3 = vil_year_tr$mean[vil_year_tr$T == "Low Cash"][1]
vil_year_tr4 = vil_year_tr$mean[vil_year_tr$T == "High Cash"][1]

# standard deviations
vil_year_total_sd = sd(as.numeric(combo$Village_Visit_Year), na.rm = TRUE)

vil_year_tr_sd <- combo %>%
  group_by(T) %>%
  summarise(mean = sd(Village_Visit_Year,  na.rm = TRUE))

vil_year_tr1_sd = vil_year_tr_sd$mean[vil_year_tr_sd$T == "Placebo"][1]
vil_year_tr2_sd = vil_year_tr_sd$mean[vil_year_tr_sd$T == "CDC health"][1]
vil_year_tr3_sd = vil_year_tr_sd$mean[vil_year_tr_sd$T == "Low Cash"][1]
vil_year_tr4_sd = vil_year_tr_sd$mean[vil_year_tr_sd$T == "High Cash"][1]

##11: 
# Percent of people having family in other villages 
fami_vil_full = combo %>%  group_by(Village_Family) %>% summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))
fami_vil_full = fami_vil_full$percentage[fami_vil_full$Village_Family == "Yes"][1]

fami_vil_treatment <- combo %>%  group_by(T, Village_Family) %>%
  summarise(n = n()) %>%   mutate(percentage = 100 * n / sum(n))
fami_vil_pla <- fami_vil_treatment$percentage[fami_vil_treatment$Village_Family == "Yes" & fami_vil_treatment$T== "Placebo"][1]
fami_vil_cdc <- fami_vil_treatment$percentage[fami_vil_treatment$Village_Family == "Yes" & fami_vil_treatment$T == "CDC health"][1]
fami_vil_lc <- fami_vil_treatment$percentage[fami_vil_treatment$Village_Family == "Yes" & fami_vil_treatment$T == "Low Cash"][1]
fami_vil_hc <- fami_vil_treatment$percentage[fami_vil_treatment$Village_Family == "Yes" & fami_vil_treatment$T == "High Cash"][1]

# Standard deviations: 
fam_tab = combo[,c("T", "Village_Family")]
fam_tab$family = ifelse(fam_tab$Village_Family=="Yes", 1, 0)
fam_sd <- fam_tab %>%
  group_by(T) %>%
  summarise(sd = sd(family, na.rm = TRUE))
fam_pla_sd <- as.numeric(fam_sd[which(fam_sd$T=="Placebo"),][2])*100
fam_cdc_sd <- as.numeric(fam_sd[which(fam_sd$T=="CDC health"),][2])*100
fam_lc_sd <- as.numeric(fam_sd[which(fam_sd$T=="Low Cash"),][2])*100
fam_hc_sd <-as.numeric(fam_sd[which(fam_sd$T=="High Cash"),][2])*100
fam_total_sd = sd(fam_tab$family, na.rm = TRUE)*100


#12: 
# Percentage of having whatsapp: 
whatsapp_full = combo %>%  group_by(WhatsApp) %>% summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))
whatsapp_full = whatsapp_full$percentage[whatsapp_full$WhatsApp == 1][1]

whatsapp_treatment <- combo %>%  group_by(T, WhatsApp) %>%
  summarise(n = n()) %>%   mutate(percentage = 100 * n / sum(n))
whatsapp_pla <- whatsapp_treatment$percentage[whatsapp_treatment$WhatsApp == 1 & whatsapp_treatment$T == "Placebo"][1]
whatsapp_cdc <- whatsapp_treatment$percentage[whatsapp_treatment$WhatsApp == 1 & whatsapp_treatment$T == "CDC health"][1]
whatsapp_lc <- whatsapp_treatment$percentage[whatsapp_treatment$WhatsApp == 1 & whatsapp_treatment$T == "Low Cash"][1]
whatsapp_hc <- whatsapp_treatment$percentage[whatsapp_treatment$WhatsApp == 1 & whatsapp_treatment$T == "High Cash"][1]

# Standard deviations: 
whatsapp_tab = combo[,c("T", "WhatsApp")]
whatsapp_tab$whatsapp = ifelse(whatsapp_tab$WhatsApp==1, 1, 0)
whatsapp_sd <- whatsapp_tab %>%
  group_by(T) %>%
  summarise(sd = sd(whatsapp, na.rm = TRUE))
whatsapp_pla_sd <- as.numeric(whatsapp_sd[which(whatsapp_sd$T=="Placebo"),][2])*100
whatsapp_cdc_sd <- as.numeric(whatsapp_sd[which(whatsapp_sd$T=="CDC health"),][2])*100
whatsapp_lc_sd <- as.numeric(whatsapp_sd[which(whatsapp_sd$T=="Low Cash"),][2])*100
whatsapp_hc_sd <-as.numeric(whatsapp_sd[which(whatsapp_sd$T=="High Cash"),][2])*100
whatsapp_total_sd = sd(whatsapp_tab$whatsapp, na.rm = TRUE)*100


##13: 
# how often do you use Whatsapp - % at least once per month
combo_small = combo
combo_small$WhatsApp_Use[which(combo_small$WhatsApp_Use=="Never")] = NA
combo_small = combo_small[-which(is.na(combo_small$WhatsApp_Use)==TRUE),]
whatsapp_use_full = combo_small %>%  group_by(WhatsApp_Use) %>% summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))
whatsapp_use_full = whatsapp_use_full$percentage[whatsapp_use_full$WhatsApp_Use == "A few times each week"][1] +
  whatsapp_use_full$percentage[whatsapp_use_full$WhatsApp_Use == "A few times every day"][1] +
  whatsapp_use_full$percentage[whatsapp_use_full$WhatsApp_Use == "About once a day"][1] +
  whatsapp_use_full$percentage[whatsapp_use_full$WhatsApp_Use == "About once a week"][1] +
  whatsapp_use_full$percentage[whatsapp_use_full$WhatsApp_Use == "Many times, every day"][1] +
  whatsapp_use_full$percentage[whatsapp_use_full$WhatsApp_Use== "Once or twice a month"][1]
whatsapp_use_treatment = combo_small %>%  group_by(T, WhatsApp_Use) %>%
  summarise(n = n()) %>%   mutate(percentage = 100 * n / sum(n))

whatsapp_use_tr1 = sum(whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "A few times each week" & whatsapp_use_treatment$T == "Placebo"][1],
                       whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "A few times every day" & whatsapp_use_treatment$T == "Placebo"][1],
                       whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "About once a day"& whatsapp_use_treatment$T == "Placebo"][1],
                       whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "About once a week"& whatsapp_use_treatment$T == "Placebo"][1],
                       whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "Many times, every day"& whatsapp_use_treatment$T == "Placebo"][1],
                       whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "Once or twice a month"& whatsapp_use_treatment$T == "Placebo"][1], na.rm =TRUE)

whatsapp_use_tr2 = sum(whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "A few times each week" & whatsapp_use_treatment$T == "CDC health"][1],
                       whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "A few times every day" & whatsapp_use_treatment$T == "CDC health"][1],
                       whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "About once a day"& whatsapp_use_treatment$T == "CDC health"][1],
                       whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "About once a week"& whatsapp_use_treatment$T == "CDC health"][1],
                       whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "Many times, every day"& whatsapp_use_treatment$T== "CDC health"][1],
                       whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "Once or twice a month"& whatsapp_use_treatment$T== "CDC health"][1], na.rm =TRUE)

whatsapp_use_tr3 = sum(whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "A few times each week" & whatsapp_use_treatment$T == "Low Cash" ][1],
                       whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "A few times every day" & whatsapp_use_treatment$T == "Low Cash"][1],
                       whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "About once a day"& whatsapp_use_treatment$T == "Low Cash"][1],
                       whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "About once a week"& whatsapp_use_treatment$T == "Low Cash"][1],
                       whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "Many times, every day"& whatsapp_use_treatment$T == "Low Cash"][1],
                       whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "Once or twice a month"& whatsapp_use_treatment$T == "Low Cash"][1], na.rm = TRUE)

whatsapp_use_tr4 = sum(whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "A few times each week" & whatsapp_use_treatment$T == "High Cash" ][1], 
                       whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "A few times every day" & whatsapp_use_treatment$T == "High Cash"][1],
                       whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "About once a day"& whatsapp_use_treatment$T == "High Cash"][1],
                       whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "About once a week"& whatsapp_use_treatment$T == "High Cash"][1],
                       whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "Many times, every day"& whatsapp_use_treatment$T == "High Cash"][1],
                       whatsapp_use_treatment$percentage[whatsapp_use_treatment$WhatsApp_Use == "Once or twice a month"& whatsapp_use_treatment$T == "High Cash"][1], na.rm = TRUE)

w_cmb = combo_small[,c("T","WhatsApp_Use")]
w_cmb$use = ifelse(w_cmb$WhatsApp_Use %in% c("A few times each week",
                                             "A few times every day", 
                                             "About once a day",
                                             "About once a week", "Many times, every day",
                                             "Once or twice a month") , 1, 0)
w_cmb_sd <- w_cmb %>%
  group_by(T) %>%
  summarise(sd = sd(use, na.rm = TRUE)) 

w_pla_sd = as.numeric(w_cmb_sd[which(w_cmb_sd$T=="Placebo"),][2])*100
w_cdc_sd = as.numeric(w_cmb_sd[which(w_cmb_sd$T=="CDC health"),][2])*100
w_lc_sd = as.numeric(w_cmb_sd[which(w_cmb_sd$T=="Low Cash"),][2])*100
w_hc_sd = as.numeric(w_cmb_sd[which(w_cmb_sd$T=="High Cash"),][2])*100
w_total_sd = sd(w_cmb$use, na.rm = TRUE)*100

#facebook
combo_small = combo
combo_small$Facebook = ifelse(is.na(combo$Facebook), "No", "Yes")
fb = combo_small %>%  group_by(Facebook) %>% summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))
fb_full = fb$percentage[fb$Facebook == "Yes"][1]

fb_treatment <- combo_small %>%  group_by(T, Facebook) %>%
  summarise(n = n()) %>%   mutate(percentage = 100 * n / sum(n))

fb_vil_pla <- fb_treatment$percentage[fb_treatment$Facebook == "Yes" & fb_treatment$T== "Placebo"][1]
fb_vil_cdc <- fb_treatment$percentage[fb_treatment$Facebook == "Yes" & fb_treatment$T == "CDC health"][1]
fb_vil_lc <- fb_treatment$percentage[fb_treatment$Facebook == "Yes" & fb_treatment$T == "Low Cash"][1]
fb_vil_hc <- fb_treatment$percentage[fb_treatment$Facebook == "Yes" & fb_treatment$T == "High Cash"][1]

# Standard deviations: 
fb_tab = combo_small[,c("T", "Facebook")]
fb_tab$Facebook = ifelse(fb_tab$Facebook=="Yes", 1, 0)
fb_sd <- fb_tab %>%
  group_by(T) %>%
  summarise(sd = sd(Facebook, na.rm = TRUE))
fb_pla_sd <- as.numeric(fb_sd[which(fb_sd$T=="Placebo"),][2])*100
fb_cdc_sd <- as.numeric(fb_sd[which(fb_sd$T=="CDC health"),][2])*100
fb_lc_sd <- as.numeric(fb_sd[which(fb_sd$T=="Low Cash"),][2])*100
fb_hc_sd <-as.numeric(fb_sd[which(fb_sd$T=="High Cash"),][2])*100
fb_total_sd = sd(fb_tab$Facebook, na.rm = TRUE)*100


# Add 1: 
#COVID_Discuss_Family
df_vil_full = combo %>%  group_by(COVID_Discuss_Family) %>% summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))
df_vil_full = df_vil_full$percentage[df_vil_full$COVID_Discuss_Family == "Yes"][1]

df_vil_treatment <- combo %>%  group_by(T, COVID_Discuss_Family) %>%
  summarise(n = n()) %>%   mutate(percentage = 100 * n / sum(n))
df_vil_pla <- df_vil_treatment$percentage[df_vil_treatment$COVID_Discuss_Family == "Yes" & df_vil_treatment$T== "Placebo"][1]
df_vil_cdc <- df_vil_treatment$percentage[df_vil_treatment$COVID_Discuss_Family == "Yes" & df_vil_treatment$T == "CDC health"][1]
df_vil_lc <- df_vil_treatment$percentage[df_vil_treatment$COVID_Discuss_Family == "Yes" & df_vil_treatment$T == "Low Cash"][1]
df_vil_hc <- df_vil_treatment$percentage[df_vil_treatment$COVID_Discuss_Family == "Yes" & df_vil_treatment$T == "High Cash"][1]

# Standard deviations: 
df_tab = combo[,c("T", "COVID_Discuss_Family")]
df_tab$COVID_Discuss_Family = ifelse(df_tab$COVID_Discuss_Family=="Yes", 1, 0)
df_sd <- df_tab %>%
  group_by(T) %>%
  summarise(sd = sd(COVID_Discuss_Family, na.rm = TRUE))
df_pla_sd <- as.numeric(df_sd[which(df_sd$T=="Placebo"),][2])*100
df_cdc_sd <- as.numeric(df_sd[which(df_sd$T=="CDC health"),][2])*100
df_lc_sd <- as.numeric(df_sd[which(df_sd$T=="Low Cash"),][2])*100
df_hc_sd <-as.numeric(df_sd[which(df_sd$T=="High Cash"),][2])*100
df_total_sd = sd(df_tab$COVID_Discuss_Family, na.rm = TRUE)*100

# Add 1.2:
combo_small = combo[-which(is.na(combo$COVID_Family_Frequency)==TRUE),]
diss1 = combo_small %>%  group_by(COVID_Family_Frequency) %>% summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))

diss1_full = diss1$percentage[diss1$COVID_Family_Frequency == "At least once a week"][1] +
  diss1$percentage[diss1$COVID_Family_Frequency == "Couple times a week"][1] +
  diss1$percentage[diss1$COVID_Family_Frequency == "Every day"][1]

diss1_treatment = combo_small %>%  group_by(T, COVID_Family_Frequency) %>%
  summarise(n = n()) %>%   mutate(percentage = 100 * n / sum(n))

diss1_tr1 = sum(diss1_treatment$percentage[diss1_treatment$COVID_Family_Frequency == "At least once a week" & diss1_treatment$T == "Placebo"][1],
                diss1_treatment$percentage[diss1_treatment$COVID_Family_Frequency == "Couple times a week" & diss1_treatment$T == "Placebo"][1],
                diss1_treatment$percentage[diss1_treatment$COVID_Family_Frequency == "Every day"& diss1_treatment$T == "Placebo"][1])

diss1_tr2 = sum(diss1_treatment$percentage[diss1_treatment$COVID_Family_Frequency == "At least once a week" & diss1_treatment$T == "CDC health"][1],
                diss1_treatment$percentage[diss1_treatment$COVID_Family_Frequency == "Couple times a week" & diss1_treatment$T == "CDC health"][1],
                diss1_treatment$percentage[diss1_treatment$COVID_Family_Frequency == "Every day"& diss1_treatment$T == "CDC health"][1])

diss1_tr3 = sum(diss1_treatment$percentage[diss1_treatment$COVID_Family_Frequency == "At least once a week" & diss1_treatment$T == "Low Cash"][1],
                diss1_treatment$percentage[diss1_treatment$COVID_Family_Frequency == "Couple times a week" & diss1_treatment$T == "Low Cash"][1],
                diss1_treatment$percentage[diss1_treatment$COVID_Family_Frequency == "Every day"& diss1_treatment$T == "Low Cash"][1])

diss1_tr4 = sum(diss1_treatment$percentage[diss1_treatment$COVID_Family_Frequency == "At least once a week" & diss1_treatment$T == "High Cash"][1],
                diss1_treatment$percentage[diss1_treatment$COVID_Family_Frequency == "Couple times a week" & diss1_treatment$T == "High Cash"][1],
                diss1_treatment$percentage[diss1_treatment$COVID_Family_Frequency == "Every day"& diss1_treatment$T == "High Cash"][1])

diss1_cmb = combo_small[,c("T","COVID_Family_Frequency")]
diss1_cmb$use = ifelse(diss1_cmb$COVID_Family_Frequency %in% c("At least once a week",
                                                               "Couple times a week", 
                                                               "Every day") , 1, 0)
diss1_cmb_sd <- diss1_cmb %>%
  group_by(T) %>%
  summarise(sd = sd(use, na.rm = TRUE)) 

diss1_pla_sd = as.numeric(diss1_cmb_sd[which(diss1_cmb_sd$T=="Placebo"),][2])*100
diss1_cdc_sd = as.numeric(diss1_cmb_sd[which(diss1_cmb_sd$T=="CDC health"),][2])*100
diss1_lc_sd = as.numeric(diss1_cmb_sd[which(diss1_cmb_sd$T=="Low Cash"),][2])*100
diss1_hc_sd = as.numeric(diss1_cmb_sd[which(diss1_cmb_sd$T=="High Cash"),][2])*100
diss1_total_sd = sd(diss1_cmb$use, na.rm = TRUE)*100


# Add 2: 
#COVID_Discuss_Family
df2_vil_full = combo %>%  group_by(COVID_Discuss_Friends) %>% summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))
df2_vil_full = df2_vil_full$percentage[df2_vil_full$COVID_Discuss_Friends == "Yes"][1]

df2_vil_treatment <- combo %>%  group_by(T, COVID_Discuss_Friends) %>%
  summarise(n = n()) %>%   mutate(percentage = 100 * n / sum(n))
df2_vil_pla <- df2_vil_treatment$percentage[df2_vil_treatment$COVID_Discuss_Friends == "Yes" & df2_vil_treatment$T== "Placebo"][1]
df2_vil_cdc <- df2_vil_treatment$percentage[df2_vil_treatment$COVID_Discuss_Friends == "Yes" & df2_vil_treatment$T == "CDC health"][1]
df2_vil_lc <- df2_vil_treatment$percentage[df2_vil_treatment$COVID_Discuss_Friends == "Yes" & df2_vil_treatment$T == "Low Cash"][1]
df2_vil_hc <- df2_vil_treatment$percentage[df2_vil_treatment$COVID_Discuss_Friends == "Yes" & df2_vil_treatment$T == "High Cash"][1]

# Standard deviations: 
df2_tab = combo[,c("T", "COVID_Discuss_Friends")]
df2_tab$COVID_Discuss_Friends = ifelse(df2_tab$COVID_Discuss_Friends=="Yes", 1, 0)
df2_sd <- df2_tab %>%
  group_by(T) %>%
  summarise(sd = sd(COVID_Discuss_Friends, na.rm = TRUE))
df2_pla_sd <- as.numeric(df2_sd[which(df2_sd$T=="Placebo"),][2])*100
df2_cdc_sd <- as.numeric(df2_sd[which(df2_sd$T=="CDC health"),][2])*100
df2_lc_sd <- as.numeric(df2_sd[which(df2_sd$T=="Low Cash"),][2])*100
df2_hc_sd <-as.numeric(df2_sd[which(df2_sd$T=="High Cash"),][2])*100
df2_total_sd = sd(df2_tab$COVID_Discuss_Friends, na.rm = TRUE)*100

# Add 2.2: 
combo_small = combo[-which(is.na(combo$COVID_Friends_Frequency)==TRUE),]
diss2 = combo_small %>%  group_by(COVID_Friends_Frequency) %>% summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))

diss2_full = diss2$percentage[diss2$COVID_Friends_Frequency == "At least once a week"][1] +
  diss2$percentage[diss2$COVID_Friends_Frequency == "Couple times a week"][1] +
  diss2$percentage[diss2$COVID_Friends_Frequency == "Every day"][1]

diss2_treatment = combo_small %>%  group_by(T, COVID_Friends_Frequency) %>%
  summarise(n = n()) %>%   mutate(percentage = 100 * n / sum(n))

diss2_tr1 = sum(diss2_treatment$percentage[diss2_treatment$COVID_Friends_Frequency == "At least once a week" & diss2_treatment$T == "Placebo"][1],
                diss2_treatment$percentage[diss2_treatment$COVID_Friends_Frequency == "Couple times a week" & diss2_treatment$T == "Placebo"][1],
                diss2_treatment$percentage[diss2_treatment$COVID_Friends_Frequency == "Every day"& diss2_treatment$T == "Placebo"][1])

diss2_tr2 = sum(diss2_treatment$percentage[diss2_treatment$COVID_Friends_Frequency == "At least once a week" & diss2_treatment$T == "CDC health"][1],
                diss2_treatment$percentage[diss2_treatment$COVID_Friends_Frequency == "Couple times a week" & diss2_treatment$T == "CDC health"][1],
                diss2_treatment$percentage[diss2_treatment$COVID_Friends_Frequency == "Every day"& diss2_treatment$T == "CDC health"][1])

diss2_tr3 = sum(diss2_treatment$percentage[diss2_treatment$COVID_Friends_Frequency == "At least once a week" & diss2_treatment$T == "Low Cash"][1],
                diss2_treatment$percentage[diss2_treatment$COVID_Friends_Frequency == "Couple times a week" & diss2_treatment$T == "Low Cash"][1],
                diss2_treatment$percentage[diss2_treatment$COVID_Friends_Frequency == "Every day"& diss2_treatment$T == "Low Cash"][1])

diss2_tr4 = sum(diss2_treatment$percentage[diss2_treatment$COVID_Friends_Frequency == "At least once a week" & diss2_treatment$T == "High Cash"][1],
                diss2_treatment$percentage[diss2_treatment$COVID_Friends_Frequency == "Couple times a week" & diss2_treatment$T == "High Cash"][1],
                diss2_treatment$percentage[diss2_treatment$COVID_Friends_Frequency == "Every day"& diss2_treatment$T == "High Cash"][1])

diss2_cmb = combo_small[,c("T","COVID_Friends_Frequency")]
diss2_cmb$use = ifelse(diss2_cmb$COVID_Friends_Frequency %in% c("At least once a week",
                                                                "Couple times a week", 
                                                                "Every day") , 1, 0)
diss2_cmb_sd <- diss2_cmb %>%
  group_by(T) %>%
  summarise(sd = sd(use, na.rm = TRUE)) 

diss2_pla_sd = as.numeric(diss2_cmb_sd[which(diss2_cmb_sd$T=="Placebo"),][2])*100
diss2_cdc_sd = as.numeric(diss2_cmb_sd[which(diss2_cmb_sd$T=="CDC health"),][2])*100
diss2_lc_sd = as.numeric(diss2_cmb_sd[which(diss2_cmb_sd$T=="Low Cash"),][2])*100
diss2_hc_sd = as.numeric(diss2_cmb_sd[which(diss2_cmb_sd$T=="High Cash"),][2])*100
diss2_total_sd = sd(diss2_cmb$use, na.rm = TRUE)*100


# Add 3: 
#COVID_Village
df3_vil_full = combo %>%  group_by(COVID_Villages) %>% summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))
df3_vil_full = df3_vil_full$percentage[df3_vil_full$COVID_Villages == "Yes"][1]

df3_vil_treatment <- combo %>%  group_by(T, COVID_Villages) %>%
  summarise(n = n()) %>%   mutate(percentage = 100 * n / sum(n))
df3_vil_pla <- df3_vil_treatment$percentage[df3_vil_treatment$COVID_Villages == "Yes" & df3_vil_treatment$T== "Placebo"][1]
df3_vil_cdc <- df3_vil_treatment$percentage[df3_vil_treatment$COVID_Villages == "Yes" & df3_vil_treatment$T == "CDC health"][1]
df3_vil_lc <- df3_vil_treatment$percentage[df3_vil_treatment$COVID_Villages == "Yes" & df3_vil_treatment$T == "Low Cash"][1]
df3_vil_hc <- df3_vil_treatment$percentage[df3_vil_treatment$COVID_Villages == "Yes" & df3_vil_treatment$T == "High Cash"][1]

# Standard deviations: 
df3_tab = combo[,c("T", "COVID_Villages")]
df3_tab$COVID_Villages = ifelse(df3_tab$COVID_Villages=="Yes", 1, 0)
df3_sd <- df3_tab %>%
  group_by(T) %>%
  summarise(sd = sd(COVID_Villages, na.rm = TRUE))
df3_pla_sd <- as.numeric(df3_sd[which(df3_sd$T=="Placebo"),][2])*100
df3_cdc_sd <- as.numeric(df3_sd[which(df3_sd$T=="CDC health"),][2])*100
df3_lc_sd <- as.numeric(df3_sd[which(df3_sd$T=="Low Cash"),][2])*100
df3_hc_sd <-as.numeric(df3_sd[which(df3_sd$T=="High Cash"),][2])*100
df3_total_sd = sd(df3_tab$COVID_Villages, na.rm = TRUE)*100

# Add 3.2: 
combo_small = combo[-which(is.na(combo$COVID_Villages_Frequency)==TRUE),]
diss3 = combo_small %>%  group_by(COVID_Villages_Frequency) %>% summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))

diss3_full = diss3$percentage[diss3$COVID_Villages_Frequency == "At least once a week"][1] +
  diss3$percentage[diss3$COVID_Villages_Frequency == "Couple times a week"][1] +
  diss3$percentage[diss3$COVID_Villages_Frequency == "Every day"][1]

diss3_treatment = combo_small %>%  group_by(T, COVID_Villages_Frequency) %>%
  summarise(n = n()) %>%   mutate(percentage = 100 * n / sum(n))

diss3_tr1 = sum(diss3_treatment$percentage[diss3_treatment$COVID_Villages_Frequency == "At least once a week" & diss3_treatment$T == "Placebo"][1],
                diss3_treatment$percentage[diss3_treatment$COVID_Villages_Frequency == "Couple times a week" & diss3_treatment$T == "Placebo"][1],
                diss3_treatment$percentage[diss3_treatment$COVID_Villages_Frequency == "Every day"& diss3_treatment$T == "Placebo"][1])

diss3_tr2 = sum(diss3_treatment$percentage[diss3_treatment$COVID_Villages_Frequency == "At least once a week" & diss3_treatment$T == "CDC health"][1],
                diss3_treatment$percentage[diss3_treatment$COVID_Villages_Frequency == "Couple times a week" & diss3_treatment$T == "CDC health"][1],
                diss3_treatment$percentage[diss3_treatment$COVID_Villages_Frequency == "Every day"& diss3_treatment$T == "CDC health"][1])

diss3_tr3 = sum(diss3_treatment$percentage[diss3_treatment$COVID_Villages_Frequency == "At least once a week" & diss3_treatment$T == "Low Cash"][1],
                diss3_treatment$percentage[diss3_treatment$COVID_Villages_Frequency == "Couple times a week" & diss3_treatment$T == "Low Cash"][1],
                diss3_treatment$percentage[diss3_treatment$COVID_Villages_Frequency == "Every day"& diss3_treatment$T == "Low Cash"][1])

diss3_tr4 = sum(diss3_treatment$percentage[diss3_treatment$COVID_Villages_Frequency == "At least once a week" & diss3_treatment$T == "High Cash"][1],
                diss3_treatment$percentage[diss3_treatment$COVID_Villages_Frequency == "Couple times a week" & diss3_treatment$T == "High Cash"][1],
                diss3_treatment$percentage[diss3_treatment$COVID_Villages_Frequency == "Every day"& diss3_treatment$T == "High Cash"][1])

diss3_cmb = combo_small[,c("T","COVID_Villages_Frequency")]
diss3_cmb$use = ifelse(diss3_cmb$COVID_Villages_Frequency %in% c("At least once a week",
                                                                 "Couple times a week", 
                                                                 "Every day") , 1, 0)
diss3_cmb_sd <- diss3_cmb %>%
  group_by(T) %>%
  summarise(sd = sd(use, na.rm = TRUE)) 

diss3_pla_sd = as.numeric(diss3_cmb_sd[which(diss3_cmb_sd$T=="Placebo"),][2])*100
diss3_cdc_sd = as.numeric(diss3_cmb_sd[which(diss3_cmb_sd$T=="CDC health"),][2])*100
diss3_lc_sd = as.numeric(diss3_cmb_sd[which(diss3_cmb_sd$T=="Low Cash"),][2])*100
diss3_hc_sd = as.numeric(diss3_cmb_sd[which(diss3_cmb_sd$T=="High Cash"),][2])*100
diss3_total_sd = sd(diss3_cmb$use, na.rm = TRUE)*100


# Add 4: 
#combo_small = combo[-which(is.na(combo$COVID_Villages_Frequency)==TRUE),]
diss4 = combo %>%  group_by(Heard_COVID_Dangerous) %>% summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))

diss4_full = diss4$percentage[diss4$Heard_COVID_Dangerous == "Often"][1] +
  diss4$percentage[diss4$Heard_COVID_Dangerous == "Very Often"][1] 

diss4_treatment = combo %>%  group_by(T, Heard_COVID_Dangerous) %>%
  summarise(n = n()) %>%   mutate(percentage = 100 * n / sum(n))

diss4_tr1 = sum(diss4_treatment$percentage[diss4_treatment$Heard_COVID_Dangerous == "Often" & diss4_treatment$T == "Placebo"][1],
                diss4_treatment$percentage[diss4_treatment$Heard_COVID_Dangerous == "Very Often" & diss4_treatment$T == "Placebo"][1])

diss4_tr2 = sum(diss4_treatment$percentage[diss4_treatment$Heard_COVID_Dangerous == "Often" & diss4_treatment$T == "CDC health"][1],
                diss4_treatment$percentage[diss4_treatment$Heard_COVID_Dangerous == "Very Often" & diss4_treatment$T == "CDC health"][1])

diss4_tr3 = sum(diss4_treatment$percentage[diss4_treatment$Heard_COVID_Dangerous == "Often" & diss4_treatment$T == "Low Cash"][1],
                diss4_treatment$percentage[diss4_treatment$Heard_COVID_Dangerous == "Very Often" & diss4_treatment$T == "Low Cash"][1])

diss4_tr4 = sum(diss4_treatment$percentage[diss4_treatment$Heard_COVID_Dangerous == "Often" & diss4_treatment$T == "High Cash"][1],
                diss4_treatment$percentage[diss4_treatment$Heard_COVID_Dangerous == "Very Often" & diss4_treatment$T == "High Cash"][1])

diss4_cmb = combo_small[,c("T","Heard_COVID_Dangerous")]
diss4_cmb$use = ifelse(diss4_cmb$Heard_COVID_Dangerous %in% c("Often",
                                                              "Very Often") , 1, 0)
diss4_cmb_sd <- diss4_cmb %>%
  group_by(T) %>%
  summarise(sd = sd(use, na.rm = TRUE)) 

diss4_pla_sd = as.numeric(diss4_cmb_sd[which(diss4_cmb_sd$T=="Placebo"),][2])*100
diss4_cdc_sd = as.numeric(diss4_cmb_sd[which(diss4_cmb_sd$T=="CDC health"),][2])*100
diss4_lc_sd = as.numeric(diss4_cmb_sd[which(diss4_cmb_sd$T=="Low Cash"),][2])*100
diss4_hc_sd = as.numeric(diss4_cmb_sd[which(diss4_cmb_sd$T=="High Cash"),][2])*100
diss4_total_sd = sd(diss4_cmb$use, na.rm = TRUE)*100

# Add 5: 
diss5 = combo %>%  group_by(Heard_COVID_Vaccine_Dangerous) %>% summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))

diss5_full = diss5$percentage[diss5$Heard_COVID_Vaccine_Dangerous == "Often"][1] +
  diss5$percentage[diss5$Heard_COVID_Vaccine_Dangerous == "Very Often"][1] 

diss5_treatment = combo %>%  group_by(T, Heard_COVID_Vaccine_Dangerous) %>%
  summarise(n = n()) %>%   mutate(percentage = 100 * n / sum(n))

diss5_tr1 = sum(diss5_treatment$percentage[diss5_treatment$Heard_COVID_Vaccine_Dangerous == "Often" & diss5_treatment$T == "Placebo"][1],
                diss5_treatment$percentage[diss5_treatment$Heard_COVID_Vaccine_Dangerous == "Very Often" & diss5_treatment$T == "Placebo"][1])

diss5_tr2 = sum(diss5_treatment$percentage[diss5_treatment$Heard_COVID_Vaccine_Dangerous == "Often" & diss5_treatment$T == "CDC health"][1],
                diss5_treatment$percentage[diss5_treatment$Heard_COVID_Vaccine_Dangerous == "Very Often" & diss5_treatment$T == "CDC health"][1])

diss5_tr3 = sum(diss5_treatment$percentage[diss5_treatment$Heard_COVID_Vaccine_Dangerous == "Often" & diss5_treatment$T == "Low Cash"][1],
                diss5_treatment$percentage[diss5_treatment$Heard_COVID_Vaccine_Dangerous == "Very Often" & diss5_treatment$T == "Low Cash"][1])

diss5_tr4 = sum(diss5_treatment$percentage[diss5_treatment$Heard_COVID_Vaccine_Dangerous == "Often" & diss5_treatment$T == "High Cash"][1],
                diss5_treatment$percentage[diss5_treatment$Heard_COVID_Vaccine_Dangerous == "Very Often" & diss5_treatment$T == "High Cash"][1])

diss5_cmb = combo_small[,c("T","Heard_COVID_Vaccine_Dangerous")]
diss5_cmb$use = ifelse(diss5_cmb$Heard_COVID_Vaccine_Dangerous %in% c("Often",
                                                                      "Very Often") , 1, 0)
diss5_cmb_sd <- diss5_cmb %>%
  group_by(T) %>%
  summarise(sd = sd(use, na.rm = TRUE)) 

diss5_pla_sd = as.numeric(diss5_cmb_sd[which(diss5_cmb_sd$T=="Placebo"),][2])*100
diss5_cdc_sd = as.numeric(diss5_cmb_sd[which(diss5_cmb_sd$T=="CDC health"),][2])*100
diss5_lc_sd = as.numeric(diss5_cmb_sd[which(diss5_cmb_sd$T=="Low Cash"),][2])*100
diss5_hc_sd = as.numeric(diss5_cmb_sd[which(diss5_cmb_sd$T=="High Cash"),][2])*100
diss5_total_sd = sd(diss5_cmb$use, na.rm = TRUE)*100

# Add 6: 
diss6 = combo %>%  group_by(COVID_Vaccine_Pay) %>% summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))

diss6_full = diss6$percentage[diss6$COVID_Vaccine_Pay == "Often"][1] +
  diss6$percentage[diss6$COVID_Vaccine_Pay == "Very Often"][1] 

diss6_treatment = combo %>%  group_by(T, COVID_Vaccine_Pay) %>%
  summarise(n = n()) %>%   mutate(percentage = 100 * n / sum(n))

diss6_tr1 = sum(diss6_treatment$percentage[diss6_treatment$COVID_Vaccine_Pay == "Often" & diss6_treatment$T == "Placebo"][1],
                diss6_treatment$percentage[diss6_treatment$COVID_Vaccine_Pay == "Very Often" & diss6_treatment$T == "Placebo"][1])
diss6_tr1
diss6_tr2 = sum(diss6_treatment$percentage[diss6_treatment$COVID_Vaccine_Pay == "Often" & diss6_treatment$T == "CDC health"][1],
                diss6_treatment$percentage[diss6_treatment$COVID_Vaccine_Pay == "Very Often" & diss6_treatment$T == "CDC health"][1])
diss6_tr2
diss6_tr3 = sum(diss6_treatment$percentage[diss6_treatment$COVID_Vaccine_Pay == "Often" & diss6_treatment$T == "Low Cash"][1],
                diss6_treatment$percentage[diss6_treatment$COVID_Vaccine_Pay == "Very Often" & diss6_treatment$T == "Low Cash"][1])
diss6_tr3
diss6_tr4 = sum(diss6_treatment$percentage[diss6_treatment$COVID_Vaccine_Pay == "Often" & diss6_treatment$T == "High Cash"][1],
                diss6_treatment$percentage[diss6_treatment$COVID_Vaccine_Pay == "Very Often" & diss6_treatment$T == "High Cash"][1])
diss6_tr4
diss6_cmb = combo_small[,c("T","COVID_Vaccine_Pay")]
diss6_cmb$use = ifelse(diss6_cmb$COVID_Vaccine_Pay %in% c("Often",
                                                          "Very Often") , 1, 0)
diss6_cmb_sd <- diss6_cmb %>%
  group_by(T) %>%
  summarise(sd = sd(use, na.rm = TRUE)) 

diss6_pla_sd = as.numeric(diss6_cmb_sd[which(diss6_cmb_sd$T=="Placebo"),][2])*100
diss6_pla_sd
diss6_cdc_sd = as.numeric(diss6_cmb_sd[which(diss6_cmb_sd$T=="CDC health"),][2])*100
diss6_cdc_sd
diss6_lc_sd = as.numeric(diss6_cmb_sd[which(diss6_cmb_sd$T=="Low Cash"),][2])*100
diss6_lc_sd
diss6_hc_sd = as.numeric(diss6_cmb_sd[which(diss6_cmb_sd$T=="High Cash"),][2])*100
diss6_hc_sd
diss6_total_sd = sd(diss6_cmb$use, na.rm = TRUE)*100
diss6_total_sd
# Add 7: last
diss7 = combo %>%  group_by(COVID_Vaccine_NotEffective) %>% summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))

diss7_full = diss7$percentage[diss7$COVID_Vaccine_NotEffective == "Often"][1] +
  diss7$percentage[diss7$COVID_Vaccine_NotEffective == "Very Often"][1] 

diss7_treatment = combo %>%  group_by(T, COVID_Vaccine_NotEffective) %>%
  summarise(n = n()) %>%   mutate(percentage = 100 * n / sum(n))

diss7_tr1 = sum(diss7_treatment$percentage[diss7_treatment$COVID_Vaccine_NotEffective == "Often" & diss7_treatment$T == "Placebo"][1],
                diss7_treatment$percentage[diss7_treatment$COVID_Vaccine_NotEffective == "Very Often" & diss7_treatment$T == "Placebo"][1])

diss7_tr2 = sum(diss7_treatment$percentage[diss7_treatment$COVID_Vaccine_NotEffective == "Often" & diss7_treatment$T == "CDC health"][1],
                diss7_treatment$percentage[diss7_treatment$COVID_Vaccine_NotEffective == "Very Often" & diss7_treatment$T == "CDC health"][1])

diss7_tr3 = sum(diss7_treatment$percentage[diss7_treatment$COVID_Vaccine_NotEffective == "Often" & diss7_treatment$T == "Low Cash"][1],
                diss7_treatment$percentage[diss7_treatment$COVID_Vaccine_NotEffective == "Very Often" & diss7_treatment$T == "Low Cash"][1])

diss7_tr4 = sum(diss7_treatment$percentage[diss7_treatment$COVID_Vaccine_NotEffective == "Often" & diss7_treatment$T == "High Cash"][1],
                diss7_treatment$percentage[diss7_treatment$COVID_Vaccine_NotEffective == "Very Often" & diss7_treatment$T == "High Cash"][1])

diss7_cmb = combo_small[,c("T","COVID_Vaccine_NotEffective")]
diss7_cmb$use = ifelse(diss7_cmb$COVID_Vaccine_NotEffective %in% c("Often",
                                                                   "Very Often") , 1, 0)
diss7_cmb_sd <- diss7_cmb %>%
  group_by(T) %>%
  summarise(sd = sd(use, na.rm = TRUE)) 

diss7_pla_sd = as.numeric(diss7_cmb_sd[which(diss7_cmb_sd$T=="Placebo"),][2])*100
diss7_cdc_sd = as.numeric(diss7_cmb_sd[which(diss7_cmb_sd$T=="CDC health"),][2])*100
diss7_lc_sd = as.numeric(diss7_cmb_sd[which(diss7_cmb_sd$T=="Low Cash"),][2])*100
diss7_hc_sd = as.numeric(diss7_cmb_sd[which(diss7_cmb_sd$T=="High Cash"),][2])*100
diss7_total_sd = sd(diss7_cmb$use, na.rm = TRUE)*100


### Responsibility things:
resp_total = mean(as.numeric(combo$COVID_Responsibility), na.rm = TRUE)
combo$COVID_Responsibility = as.numeric(combo$COVID_Responsibility)

resp_tr <- combo %>%
  group_by(T) %>%
  summarise(mean = mean(COVID_Responsibility,  na.rm = TRUE))

resp_tr1 = resp_tr$mean[resp_tr$T == "Placebo"][1]
resp_tr2 = resp_tr$mean[resp_tr$T == "CDC health"][1]
resp_tr3 = resp_tr$mean[resp_tr$T == "Low Cash"][1]
resp_tr4 = resp_tr$mean[resp_tr$T == "High Cash"][1]

# standard deviations
resp_total_sd = sd(as.numeric(combo$COVID_Responsibility), na.rm = TRUE)

resp_tr_sd <- combo %>%
  group_by(T) %>%
  summarise(mean = sd(COVID_Responsibility,  na.rm = TRUE))

resp_tr1_sd = resp_tr_sd$mean[resp_tr_sd$T == "Placebo"][1]
resp_tr2_sd = resp_tr_sd$mean[resp_tr_sd$T == "CDC health"][1]
resp_tr3_sd = resp_tr_sd$mean[resp_tr_sd$T == "Low Cash"][1]
resp_tr4_sd = resp_tr_sd$mean[resp_tr_sd$T == "High Cash"][1]



### added: 
#Age total
age_total <- mean(as.numeric(combo$Age), na.rm=TRUE)

#Age per treatment
age_treatment <- combo %>%
  group_by(T) %>%
  summarise(mean = mean(Age, na.rm = TRUE))

age_pla <- age_treatment$mean[age_treatment$T == "Placebo"][1]
age_cdc <- age_treatment$mean[age_treatment$T == "CDC health"][1]
age_lc <- age_treatment$mean[age_treatment$T == "Low Cash"][1]
age_hc <- age_treatment$mean[age_treatment$T == "High Cash"][1]

## Age additional SD: 
age_sd <- combo %>%
  group_by(T) %>%
  summarise(sd = sd(Age, na.rm = TRUE))
age_pla_sd = as.numeric(na.omit(age_sd$sd[age_sd$T == "Placebo"]))
age_cdc_sd = as.numeric(na.omit(age_sd$sd[age_sd$T == "CDC health"]))
age_lc_sd = as.numeric(na.omit(age_sd$sd[age_sd$T == "Low Cash"]))
age_hc_sd = as.numeric(na.omit(age_sd$sd[age_sd$T == "High Cash"]))
age_total_sd = sd(combo$Age, na.rm=TRUE)


# % Employed total
employment_total <- combo %>%
  group_by(Q10.7) %>%
  summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))

emp_total_full <- employment_total$percentage[employment_total$Q10.7 == "Employed (full time)"][1]
emp_total_part <- employment_total$percentage[employment_total$Q10.7 == "Employed (part time)"][1]
emp_total_unemp <- employment_total$percentage[employment_total$Q10.7 == "Unemployed"][1]
#Unemployed
# % Employed per treatment
employment_treatment <- combo %>%
  group_by(T, Q10.7) %>%
  summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))

emp_pla_full <- employment_treatment$percentage[employment_treatment$Q10.7 == "Employed (full time)" & employment_treatment$T == "Placebo"][1]
emp_pla_part <- employment_treatment$percentage[employment_treatment$Q10.7 == "Employed (part time)" & employment_treatment$T == "Placebo"][1]
emp_pla_unemp <- employment_treatment$percentage[employment_treatment$Q10.7 == "Unemployed" & employment_treatment$T == "Placebo"][1]

emp_cdc_full <- employment_treatment$percentage[employment_treatment$Q10.7 == "Employed (full time)" & employment_treatment$T == "CDC health"][1]
emp_cdc_part <- employment_treatment$percentage[employment_treatment$Q10.7 == "Employed (part time)" & employment_treatment$T == "CDC health"][1]
emp_cdc_unemp <- employment_treatment$percentage[employment_treatment$Q10.7 == "Unemployed" & employment_treatment$T == "CDC health"][1]

emp_lc_full <- employment_treatment$percentage[employment_treatment$Q10.7 == "Employed (full time)" & employment_treatment$T == "Low Cash"][1]
emp_lc_part <- employment_treatment$percentage[employment_treatment$Q10.7 == "Employed (part time)" & employment_treatment$T == "Low Cash"][1]
emp_lc_unemp <- employment_treatment$percentage[employment_treatment$Q10.7 == "Unemployed" & employment_treatment$T == "Low Cash"][1]

emp_hc_full <- employment_treatment$percentage[employment_treatment$Q10.7 == "Employed (full time)" & employment_treatment$T == "High Cash"][1]
emp_hc_part <- employment_treatment$percentage[employment_treatment$Q10.7 == "Employed (part time)" & employment_treatment$T == "High Cash"][1]
emp_hc_unemp <- employment_treatment$percentage[employment_treatment$Q10.7 == "Unemployed" & employment_treatment$T == "High Cash"][1]

#### New Standard deviations for Employment variables: 
w_tab = combo[,c("T", "Q10.7")]
w_tab$Full = ifelse(w_tab$Q10.7=="Employed (full time)", 1, 0)
w_tab$Part = ifelse(w_tab$Q10.7=="Employed (part time)", 1, 0)
w_tab$UnE = ifelse(w_tab$Q10.7=="Unemployed", 1, 0)

full_sd <- w_tab %>%
  group_by(T) %>%
  summarise(sd = sd(Full, na.rm = TRUE))
part_sd <- w_tab %>%
  group_by(T) %>%
  summarise(sd = sd(Part, na.rm = TRUE))
UnE_sd <- w_tab %>%
  group_by(T) %>%
  summarise(sd = sd(UnE, na.rm = TRUE))

full_pla_sd = as.numeric(full_sd[which(full_sd$T=="Placebo"),][2])*100
full_cdc_sd = as.numeric(full_sd[which(full_sd$T=="CDC health"),][2])*100
full_lc_sd = as.numeric(full_sd[which(full_sd$T=="Low Cash"),][2])*100
full_hc_sd = as.numeric(full_sd[which(full_sd$T=="High Cash"),][2])*100
full_sample_sd = sd(w_tab$Full, na.rm = TRUE)*100

part_pla_sd = as.numeric(part_sd[which(part_sd$T=="Placebo"),][2])*100
part_cdc_sd = as.numeric(part_sd[which(part_sd$T=="CDC health"),][2])*100
part_lc_sd = as.numeric(part_sd[which(part_sd$T=="Low Cash"),][2])*100
part_hc_sd = as.numeric(part_sd[which(part_sd$T=="High Cash"),][2])*100
part_sample_sd = sd(w_tab$Part, na.rm = TRUE)*100

UnE_pla_sd = as.numeric(UnE_sd[which(UnE_sd$T=="Placebo"),][2])*100
UnE_cdc_sd = as.numeric(UnE_sd[which(UnE_sd$T=="CDC health"),][2])*100
UnE_lc_sd = as.numeric(UnE_sd[which(UnE_sd$T=="Low Cash"),][2])*100
UnE_hc_sd = as.numeric(UnE_sd[which(UnE_sd$T=="High Cash"),][2])*100
UnE_sample_sd = sd(w_tab$UnE, na.rm = TRUE)*100

# remove outliers
combo$Income[which(combo$Income>1000)] = NA
#Average weekly spending on food total
food_total <- mean(combo$Income, na.rm=TRUE)

#Average weekly spending on food per treatment
food_treatment <- combo %>%
  group_by(T) %>%
  summarise(mean = mean(Income, na.rm = TRUE))

food_pla <- food_treatment$mean[food_treatment$T == "Placebo"][1]
food_cdc <- food_treatment$mean[food_treatment$T == "CDC health"][1]
food_lc <- food_treatment$mean[food_treatment$T == "Low Cash"][1]
food_hc <- food_treatment$mean[food_treatment$T == "High Cash"][1]

# New added SDs: 
food_total_sd <- sd(combo$Income, na.rm=TRUE)
#Average weekly spending on food per treatment
food_treatment_sd <- combo %>%
  group_by(T) %>%
  summarise(mean = sd(Income, na.rm = TRUE))
food_pla_sd <- food_treatment_sd$mean[food_treatment_sd$T == "Placebo"][1]
food_cdc_sd <- food_treatment_sd$mean[food_treatment_sd$T == "CDC health"][1]
food_lc_sd <- food_treatment_sd$mean[food_treatment_sd$T == "Low Cash"][1]
food_hc_sd <- food_treatment_sd$mean[food_treatment_sd$T == "High Cash"][1]

# % School total
school_total <- combo %>%
  group_by(Q10.11) %>%
  summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))

#Never attended
school_total_never <- school_total$percentage[school_total$Q10.11 == "Never attended"][1]

#MiddleSchool or more
school_total_middle_more <- sum(school_total$percentage[school_total$Q10.11 == "Bachelor degree"][1],
                                school_total$percentage[school_total$Q10.11 == "JSS/JHS"][1] + school_total$percentage[school_total$Q10.11 == "Middle"][1],
                                school_total$percentage[school_total$Q10.11 == "Post-secondary diploma"][1],
                                school_total$percentage[school_total$Q10.11 == "Post graduate (Cert. Diploma Masters PHD etc)"][1],
                                school_total$percentage[school_total$Q10.11 == "Post middle/secondary certificate"][1],
                                school_total$percentage[school_total$Q10.11 == "SSS/SHS"][1],
                                school_total$percentage[school_total$Q10.11 == "Vocational/Technical/Commercial"][1], na.rm = TRUE)

# school total - never attended: 


# % School per treatment
school_treatment <- combo %>%
  group_by(T, Q10.11) %>%
  summarise(n = n()) %>%
  mutate(percentage = 100 * n / sum(n))

#Never attended
school_pla_never <- school_treatment$percentage[school_treatment$Q10.11 == "Never attended" & school_treatment$T == "Placebo"][1]
school_cdc_never <- school_treatment$percentage[school_treatment$Q10.11 == "Never attended" & school_treatment$T == "CDC health"][1]
school_lc_never <- school_treatment$percentage[school_treatment$Q10.11 == "Never attended" & school_treatment$T == "Low Cash"][1]
school_hc_never <- school_treatment$percentage[school_treatment$Q10.11 == "Never attended" & school_treatment$T == "High Cash"][1]

# New: SD for never attended - so simple bivariate variable: 
# school yes/no

w_cmb = combo[,c("T","Q10.11")]
w_cmb$Attended = ifelse(w_cmb$Q10.11 == "Never attended", 1, 0)
school_total_sd <- w_cmb %>%
  group_by(T) %>%
  summarise(sd = sd(Attended, na.rm = TRUE)) 

school_pla_never_sd = as.numeric(school_total_sd[which(school_total_sd$T=="Placebo"),][2])*100
school_cdc_never_sd = as.numeric(school_total_sd[which(school_total_sd$T=="CDC health"),][2])*100
school_lc_never_sd = as.numeric(school_total_sd[which(school_total_sd$T=="Low Cash"),][2])*100
school_hc_never_sd = as.numeric(school_total_sd[which(school_total_sd$T=="High Cash"),][2])*100
school_never_sd = sd(w_cmb$Attended, na.rm = TRUE)*100

#MiddleSchool or more

school_pla_middle_more <- sum(school_treatment$percentage[school_treatment$Q10.11 == "Bachelor degree" & school_treatment$T == "Placebo"][1], 
                              school_treatment$percentage[school_treatment$Q10.11 == "JSS/JHS" & school_treatment$T == "Placebo"][1],
                              school_treatment$percentage[school_treatment$Q10.11 == "Middle" & school_treatment$T == "Placebo"][1],
                              school_treatment$percentage[school_treatment$Q10.11 == "Post-secondary diploma" & school_treatment$T == "Placebo"][1],
                              school_treatment$percentage[school_treatment$Q10.11 == "Post graduate (Cert. Diploma Masters PHD etc)" & school_treatment$T == "Placebo"][1],
                              school_treatment$percentage[school_treatment$Q10.11 == "Post middle/secondary certificate" & school_treatment$T == "Placebo"][1],
                              school_treatment$percentage[school_treatment$Q10.11 == "SSS/SHS" & school_treatment$T == "Placebo"][1],
                              school_treatment$percentage[school_treatment$Q10.11 == "Vocational/Technical/Commercial" & school_treatment$T == "Placebo"][1],na.rm=TRUE)

school_cdc_middle_more <- sum(school_treatment$percentage[school_treatment$Q10.11 == "Bachelor degree" & school_treatment$T == "CDC health"][1], 
                              school_treatment$percentage[school_treatment$Q10.11 == "JSS/JHS" & school_treatment$T == "CDC health"][1],
                              school_treatment$percentage[school_treatment$Q10.11 == "Middle" & school_treatment$T == "CDC health"][1],
                              school_treatment$percentage[school_treatment$Q10.11 == "Post-secondary diploma" & school_treatment$T == "CDC health"][1],
                              school_treatment$percentage[school_treatment$Q10.11 == "Post graduate (Cert. Diploma Masters PHD etc)" & school_treatment$T == "CDC health"][1],
                              school_treatment$percentage[school_treatment$Q10.11 == "Post middle/secondary certificate" & school_treatment$T == "CDC health"][1],
                              school_treatment$percentage[school_treatment$Q10.11 == "SSS/SHS" & school_treatment$T == "CDC health"][1],
                              school_treatment$percentage[school_treatment$Q10.11 == "Vocational/Technical/Commercial" & school_treatment$T == "CDC health"][1], na.rm = TRUE)

school_lc_middle_more <- sum(school_treatment$percentage[school_treatment$Q10.11 == "Bachelor degree" & school_treatment$T == "Low Cash"][1], 
                             school_treatment$percentage[school_treatment$Q10.11 == "JSS/JHS" & school_treatment$T == "Low Cash"][1],
                             school_treatment$percentage[school_treatment$Q10.11 == "Middle" & school_treatment$T == "Low Cash"][1],
                             school_treatment$percentage[school_treatment$Q10.11 == "Post-secondary diploma" & school_treatment$T == "Low Cash"][1],
                             school_treatment$percentage[school_treatment$Q10.11 == "Post graduate (Cert. Diploma Masters PHD etc)" & school_treatment$T == "Low Cash"][1],
                             school_treatment$percentage[school_treatment$Q10.11 == "Post middle/secondary certificate" & school_treatment$T == "Low Cash"][1],
                             school_treatment$percentage[school_treatment$Q10.11 == "SSS/SHS" & school_treatment$T == "Low Cash"][1],
                             school_treatment$percentage[school_treatment$Q10.11 == "Vocational/Technical/Commercial" & school_treatment$T == "Low Cash"][1], na.rm = TRUE)

school_hc_middle_more <- sum(school_treatment$percentage[school_treatment$Q10.11 == "Bachelor degree" & school_treatment$T == "High Cash"][1], 
                             school_treatment$percentage[school_treatment$Q10.11 == "JSS/JHS" & school_treatment$T == "High Cash"][1],
                             school_treatment$percentage[school_treatment$Q10.11 == "Middle" & school_treatment$T == "High Cash"][1],
                             school_treatment$percentage[school_treatment$Q10.11 == "Post-secondary diploma" & school_treatment$T == "High Cash"][1],
                             school_treatment$percentage[school_treatment$Q10.11 == "Post graduate (Cert. Diploma Masters PHD etc)" & school_treatment$T == "High Cash"][1],
                             school_treatment$percentage[school_treatment$Q10.11 == "Post middle/secondary certificate" & school_treatment$T == "High Cash"][1],
                             school_treatment$percentage[school_treatment$Q10.11 == "SSS/SHS" & school_treatment$T == "High Cash"][1],
                             school_treatment$percentage[school_treatment$Q10.11 == "Vocational/Technical/Commercial" & school_treatment$T == "High Cash"][1], na.rm = TRUE)

### middle school - SD - Yes no: 
w_cmb2 = combo[,c("T","Q10.11")]
w_cmb2$Middle = ifelse(w_cmb2$Q10.11 %in% c("Vocational/Technical/Commercial",
                                            "SSS/SHS","Post middle/secondary certificate", 
                                            "Post graduate (Cert. Diploma Masters PHD etc)",
                                            "Post-secondary diploma", "Middle",
                                            "JSS/JHS", "Bachelor degree") , 1, 0)

middle_total_sd <- w_cmb2 %>%
  group_by(T) %>%
  summarise(sd = sd(Middle, na.rm = TRUE)) 

school_pla_middle_sd = as.numeric(middle_total_sd[which(middle_total_sd$T=="Placebo"),][2])*100
school_cdc_middle_sd = as.numeric(middle_total_sd[which(middle_total_sd$T=="CDC health"),][2])*100
school_lc_middle_sd = as.numeric(middle_total_sd[which(middle_total_sd$T=="Low Cash"),][2])*100
school_hc_middle_sd = as.numeric(middle_total_sd[which(middle_total_sd$T=="High Cash"),][2])*100
school_middle_sd = sd(w_cmb2$Middle, na.rm = TRUE)*100





### Build the table: 

#### Build a new final Table: 
e = c(0)
#Vectors for the table
Total_Sample <- round(c(nb_vil_full, nb_total, female_full, vaccined_full, vaccined_full2,
                        vil_month_total, vil_year_total, fami_vil_full, whatsapp_full, 
                        whatsapp_use_full, fb_full,
                        df_vil_full, diss1_full, 
                        df2_vil_full, diss2_full, 
                        df3_vil_full, diss3_full, 
                        diss4_full, 
                        diss5_full,
                        diss6_full,
                        diss7_full, 
                        resp_total,
                        age_total, emp_total_full, emp_total_part, emp_total_unemp, food_total, school_total_never, school_total_middle_more
                        
), digits=1)

Total_Sample_sd = round(c(e, e, female_total_sd,  vaccine_total_sd, vaccine_total_sd,
                          vil_month_total_sd, vil_year_total_sd, fam_total_sd, whatsapp_total_sd,
                          w_total_sd, fb_total_sd,
                          df_total_sd, diss1_total_sd, 
                          df2_total_sd, diss2_total_sd, 
                          df3_total_sd, diss3_total_sd, 
                          diss4_total_sd, 
                          diss5_total_sd,
                          diss6_total_sd, 
                          diss7_total_sd, 
                          resp_total_sd, 
                          age_total_sd, full_sample_sd, part_sample_sd, UnE_sample_sd, food_total_sd, school_never_sd, school_middle_sd
                          
), digits=1)

Placebo <- round(c(nb_vil_pla, nb_t1, female_pla, vaccine_pla, vaccine_pla2,
                   vil_month_tr1, vil_year_tr1, fami_vil_pla, whatsapp_pla,
                   whatsapp_use_tr1, fb_vil_pla,
                   df_vil_pla, diss1_tr1,
                   df2_vil_pla, diss2_tr1,
                   df3_vil_pla, diss3_tr1,
                   diss4_tr1,
                   diss5_tr1,
                   diss6_tr1, 
                   diss7_tr1,
                   resp_tr1,
                   age_pla, emp_pla_full, emp_pla_part, emp_pla_unemp, food_pla, school_pla_never, school_pla_middle_more
                   
), digits=1)

Placebo_sd <- round(c(e,e, female_pla_sd, vaccine_pla_sd, vaccine_pla_sd2,
                      vil_month_tr1_sd, vil_year_tr1_sd, fam_pla_sd, whatsapp_pla_sd,
                      w_pla_sd, fb_pla_sd, 
                      df_pla_sd, diss1_pla_sd, 
                      df2_pla_sd, diss2_pla_sd, 
                      df3_pla_sd, diss3_pla_sd, 
                      diss4_pla_sd, 
                      diss5_pla_sd, 
                      diss6_pla_sd, 
                      diss7_pla_sd, 
                      resp_tr1_sd,
                      age_pla_sd, full_pla_sd, part_pla_sd, UnE_pla_sd, food_pla_sd, school_pla_never_sd, school_pla_middle_sd 
                      
), digits=1)

Health_Message <- round(c(nb_vil_cdc, nb_t2, female_cdc, vaccine_cdc, vaccine_cdc2,
                          vil_month_tr2, vil_year_tr2, fami_vil_cdc, whatsapp_cdc,
                          whatsapp_use_tr2, fb_vil_cdc,
                          df_vil_cdc, diss1_tr2,
                          df2_vil_cdc, diss2_tr2,
                          df3_vil_cdc, diss3_tr2,
                          diss4_tr2,
                          diss5_tr2,
                          diss6_tr2, 
                          diss7_tr2,
                          resp_tr2,
                          age_cdc, emp_cdc_full, emp_cdc_part, emp_cdc_unemp, food_cdc, school_cdc_never, school_cdc_middle_more
                          
), digits=1)

Health_Message_sd <- round(c(e, e, female_cdc_sd, vaccine_cdc_sd, vaccine_cdc_sd2,
                             vil_month_tr2_sd, vil_year_tr2_sd, fam_cdc_sd, whatsapp_cdc_sd,
                             w_cdc_sd, fb_cdc_sd,
                             df_cdc_sd, diss1_cdc_sd, 
                             df2_cdc_sd, diss2_cdc_sd, 
                             df3_cdc_sd, diss3_cdc_sd, 
                             diss4_cdc_sd, 
                             diss5_cdc_sd, 
                             diss6_cdc_sd, 
                             diss7_cdc_sd,
                             resp_tr2_sd,
                             age_cdc_sd, full_cdc_sd, part_cdc_sd, UnE_cdc_sd, food_cdc_sd, school_cdc_never_sd, school_cdc_middle_sd 
                             
), digits=1)

Low_Cost <- round(c(nb_vil_lc, nb_t3, female_lc, vaccine_lc, vaccine_lc2, 
                    vil_month_tr3, vil_year_tr3, fami_vil_lc, whatsapp_lc,
                    whatsapp_use_tr3, fb_vil_lc,
                    df_vil_lc, diss1_tr3,
                    df2_vil_lc, diss2_tr3,
                    df3_vil_lc, diss3_tr3,
                    diss4_tr3,
                    diss5_tr3,
                    diss6_tr3, 
                    diss7_tr3,
                    resp_tr3,
                    age_lc, emp_lc_full, emp_lc_part, emp_lc_unemp, food_lc, school_lc_never, school_lc_middle_more
                    
), digits=1)

Low_Cost_sd <- round(c(e, e, female_lc_sd, vaccine_lc_sd, vaccine_lc_sd2,
                       vil_month_tr3_sd, vil_year_tr3_sd, fam_lc_sd, whatsapp_lc_sd,
                       w_lc_sd, fb_lc_sd, 
                       df_lc_sd, diss1_lc_sd, 
                       df2_lc_sd, diss2_lc_sd, 
                       df3_lc_sd, diss3_lc_sd, 
                       diss4_lc_sd, 
                       diss5_lc_sd, 
                       diss6_lc_sd, 
                       diss7_lc_sd,
                       resp_tr3_sd,
                       age_lc_sd, full_lc_sd, part_lc_sd, UnE_lc_sd, food_lc_sd, school_lc_never_sd, school_lc_middle_sd 
                       
), digits=1)

High_Cost <- round(c(nb_vil_hc, nb_t4, female_hc, vaccine_hc, vaccine_hc2,
                     vil_month_tr4, vil_year_tr4, fami_vil_hc, whatsapp_hc,
                     whatsapp_use_tr4, fb_vil_hc, 
                     df_vil_hc, diss1_tr4,
                     df2_vil_hc, diss2_tr4,
                     df3_vil_hc, diss3_tr4,
                     diss4_tr4,
                     diss5_tr4,
                     diss6_tr4, 
                     diss7_tr4,
                     resp_tr4,
                     age_hc, emp_hc_full, emp_hc_part, emp_hc_unemp, food_hc, school_hc_never, school_hc_middle_more
                     
), digits=1)

High_Cost_sd <- round(c(e, e, female_hc_sd, vaccine_hc_sd, vaccine_hc_sd2,
                        vil_month_tr4_sd, vil_year_tr4_sd, fam_hc_sd, whatsapp_hc_sd,
                        w_hc_sd, fb_hc_sd, 
                        df_hc_sd, diss1_hc_sd, 
                        df2_hc_sd, diss2_hc_sd, 
                        df3_hc_sd, diss3_hc_sd, 
                        diss4_hc_sd, 
                        diss5_hc_sd, 
                        diss6_hc_sd, 
                        diss7_hc_sd,
                        resp_tr4_sd,
                        age_hc_sd, full_hc_sd, part_hc_sd, UnE_hc_sd, food_hc_sd, school_hc_never_sd, school_hc_middle_sd 
                        
), digits=1)



col1 = c()
for (i in c(1:29)){
  if (i %in% c(1,2)){
    col1[i] = Total_Sample[i]
  } else {
    col1[i] = as.character(paste(Total_Sample[i],paste("(",Total_Sample_sd[i],")", sep ="")))
  }
  
}
col1

col2 = c()
for (i in c(1:29)){
  if (i %in% c(1,2)){
    col2[i] = Placebo[i]
  } else {
    col2[i] = as.character(paste(Placebo[i],paste("(",Placebo_sd[i],")", sep ="")))
  }
  
}
col2

col3 = c()
for (i in c(1:29)){
  if (i %in% c(1,2)){
    col3[i] = Health_Message[i]
  } else {
    col3[i] = as.character(paste(Health_Message[i],paste("(",Health_Message_sd[i],")", sep ="")))
  }
  
}
col3

col4 = c()
for (i in c(1:29)){
  if (i %in% c(1,2)){
    col4[i] = Low_Cost[i]
  } else {
    col4[i] = as.character(paste(Low_Cost[i],paste("(",Low_Cost_sd[i],")", sep ="")))
  }
  
}
col4

col5 = c()
for (i in c(1:29)){
  if (i %in% c(1,2)){
    col5[i] = High_Cost[i]
  } else {
    col5[i] = as.character(paste(High_Cost[i],paste("(",High_Cost_sd[i],")", sep ="")))
  }
  
}
col5

test = cbind(col1, col2, col3, col4, col5)
library(htmlTable)
htmlTable(test)

# new row names: 
img_col_names <- c("Number of Villages", "Number of Subjects", 
                   "% Female", 
                   #"% Reported Vaccinated - Dose 1",
                   "Actual Vaccination April",
                   "% Reported Vaccinated - Dose 1",
                   "Mean villages visited last month",
                   "Mean villages visited last year",
                   "% with family in other villages",
                   "% with WhatsApp", 
                   "% WhatsApp >= once per month", 
                   "% with Facebook", 
                   "COVID_Discuss_Family", 
                   "COVID_Family_Frequency",
                   "COVID_Discuss_Friends", 
                   "COVID_Friends_Frequency", 
                   "COVID_Villages",
                   "COVID_Villages_Frequency",
                   "Heard_COVID_Dangerous",
                   "Heard_COVID_Vaccine_Dangerous",
                   "COVID_Vaccine_Pay",
                   "COVID_Vaccine_NotEffective", 
                   "COVID_Responsibility", 
                   "Age", 
                   "% Employed full time", 
                   "% Employed part time",
                   "Unemployed", 
                   "Income", 
                   "% Never attended school", 
                   "% Middle school or greater")




df_fig_tt <- data.frame(img_col_names, test)
colnames(df_fig_tt) <- c("", "Total Sample", "Placebo", "Health Message", "Low Cost", "High Cost")
htmlTable(df_fig_tt)
#print.xtable(df_fig_tt, file = "Tables/Table04.tex", compress = FALSE)
#xtable(df_fig_tt, type = "latex", file = "Tables/Table04.tex")
#
require(xtable)
print.xtable(df_fig_tt[c(1:3, 5:11, 23:29),], file = "ExtData_Table5_PanelC.tex", compress = FALSE)
xtable(df_fig_tt[c(1:3, 5:11, 23:29),], type = "latex", file = "ExtData_Table5_PanelC.tex")
print(xtable(df_fig_tt[c(1:3, 5:11, 23:29),], type = "latex"), include.rownames = FALSE)















